package cn.ljn.basic.dto;

import cn.ljn.basic.util.MD5Utils;
import cn.ljn.basic.util.StrUtils;
import cn.ljn.user.domain.User;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotBlank;
import java.util.Date;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class PhoneCodeDto {
    // 手机号
    @NotBlank(message = "手机号不能为空")
    private String phone;

    @NotBlank(message = "手机验证码不能为空")
    private String smsCode;
    @NotBlank(message = "密码不能为空")
    private String password;
    @NotBlank(message = "二次密码不能为空")
    private String passwordRepeat;

    public User getUser() {
        String randomString = StrUtils.getComplexRandomString(32);
        String password = MD5Utils.encrypByMd5(randomString + this.password);

        return User.builder()
                .username(this.phone)
                .phone(this.phone)
                .state(1)
                .salt(randomString)
                .password(password)
                .createtime(new Date())
                .build();
    }

}
